package com.flycent.hqhs.ui;


import java.util.Arrays;
import java.util.List;

import net.tsz.afinal.FinalActivity;
import net.tsz.afinal.FinalDb;
import net.tsz.afinal.annotation.view.ViewInject;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.flycent.hqhs.App;
import com.flycent.hqhs.Constants;
import com.flycent.hqhs.R;
import com.flycent.hqhs.bean.Cart;
import com.flycent.hqhs.bean.CartItem;
import com.flycent.hqhs.bean.Product;
import com.flycent.hqhs.bean.PurchaseProduct;
import com.flycent.hqhs.http.WebClient;
import com.flycent.hqhs.http.WebException;
import com.flycent.hqhs.ui.view.AbsViewHolderAdapter;
import com.flycent.hqhs.ui.view.DoubleButtonDialog;
import com.flycent.hqhs.ui.view.LabelView;
import com.flycent.hqhs.ui.view.RefreshViewItemClickWrapper;
import com.flycent.hqhs.ui.view.RefreshViewLoadMoreProxy;
import com.flycent.hqhs.ui.view.RefreshViewLoadMoreProxy.OnLoadDataActionListener;
import com.flycent.hqhs.util.ContextUtil;
import com.flycent.hqhs.util.PreferenceUtil;
import com.flycent.hqhs.util.StringUtil;
import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 *   购物车
 * @author fbl
 */
@SuppressLint("ResourceAsColor") 
public class ShopCarActivity extends BaseActivity implements 
OnLoadDataActionListener,OnItemClickListener,OnItemLongClickListener{
	@ViewInject(id = R.id.cart_view ) RelativeLayout mShopCarRelat;
	@ViewInject(id = R.id.empty_cart_view) RelativeLayout mEmptyShopCaeRelat;
	@ViewInject(id = R.id.settle_accounts , click = "butClick") Button mGoShopBut;
	@ViewInject(id = R.id.setaccountBut , click = "butClick") Button mSetAccountBut;
	@ViewInject(id = R.id.buttom_image , click = "butClick") ImageView mAllSelectImage;
	@ViewInject(id = R.id.totalpriceText ) TextView totalpriceText;
	@ViewInject(id = R.id.shopcar_top_left_but , click = "butClick") ImageButton mShopCarTopLeftBut ;
	@ViewInject(id = R.id.Shopcar_top_right_btn , click = "butClick") Button mShopCarTopRightBut;

	public static ShopCarActivity instance = null;
	private String from;
	private Boolean isEmpty = false; //购物车是否为空
	private Boolean isFirst = true;
	private Cart mCart;
	private DoubleButtonDialog mDoubleDialog,mDoubleRemoveDialog;
	private boolean isAllSelect = false;

	PullToRefreshListView mRefreshListView;
	RefreshViewLoadMoreProxy mLoadMoreProxy;
	public MyShopCarAdapter mAdapter;
	private  long[] select ;
	private  long[] disSelect;
	private FinalDb db;

	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		from = getIntent().getStringExtra("from");
		setContentView(R.layout.activity_shopcar);
		FinalActivity.initInjectedView(this);
		db = (App.getInstance()).finalDb;

		instance = this;

		initView();

		mRefreshListView = (PullToRefreshListView) findViewById(R.id.lvListView);
		mRefreshListView.getRefreshableView().setSelector(new ColorDrawable(Color.TRANSPARENT));
		mRefreshListView.setOnItemClickListener(new RefreshViewItemClickWrapper.OnItemClickListener(this));
		mRefreshListView.getRefreshableView().setOnItemLongClickListener(
				new RefreshViewItemClickWrapper.OnItemLongClickListener(this));

		mAdapter = new MyShopCarAdapter(this,R.layout.item_shopcar);
		mRefreshListView.setAdapter(mAdapter);

		mLoadMoreProxy = new RefreshViewLoadMoreProxy(mRefreshListView, Mode.PULL_FROM_START,0,0);
		mLoadMoreProxy.setOnLoadDataActionListener(this);
		mLoadMoreProxy.refreshing();

	}

	private void initView() {
		//判断是是否是从别的activity跳进来的，来确定是否显示左边返回键
		if(from != null ){
			mShopCarTopLeftBut.setVisibility(View.VISIBLE);
		}else {
			mShopCarTopLeftBut.setVisibility(View.GONE);
		}


	}



	public void butClick(View v){

		// titibar 左键 返回
		if( v == mShopCarTopLeftBut){
			finish();
		}

		//titibar 右键
		if( v == mShopCarTopRightBut ){
			showRemoveDialog();
		}
		// 去首页
		if( v == mGoShopBut){
			if(from != null){
				ContextUtil.startActivity(ShopCarActivity.this, TimeLimitedSaleActivity.class);
			}
			((MainTabActivity) getParent()).tabs.check(R.id.radio_button0);
		}

		//  去结算
		if( v == mSetAccountBut ){
			if(mCart.getChosenQuantity() == 0 ){
				App.showShortToast("请只少选择一件商品");
				return;
			}

			//将购物车中勾选的商品传到提交订单的页面
			db.deleteAll(PurchaseProduct.class);
			for (int i = 0; i < mCart.getCartItems().size(); i++) {
				CartItem mit = mCart.getCartItems().get(i);
				if(mit.isChosen() ){
					//多个商品的情况 ，比如套餐
					//					if(mit.getItem() != null &&  mit.getItem().size() != 0){
					//						for (int j = 0; j < mit.getProducts().size(); j++) {
					//							cartProduct mpro = mit.getProducts().get(j);
					//							db.save(new PurchaseProduct(mpro.getId(), mpro.getGoodsId(), 
					//									mpro.getName(), mpro.getImage(), mit.getQuantity(), mpro.getPrice()));
					//						}
					//
					//					}

					// 单个商品的情况下
					if( mit.getItem() != null  ){
						db.save(new PurchaseProduct(mit.getItem().getId(), mit.getItem().getProductId(), 
								mit.getItem().getName(), mit.getItem().getImage(), mit.getQuantity(), mit.getItem().getPrice()));
					}
				}
			}

			Intent intent = new Intent(ShopCarActivity.this,SubmitOrderActivity.class);
			intent.putExtra("from", "ShopCarActivity");
			intent.putExtra("token", mCart.getToken());
			intent.putExtra("weight", mCart.getWeight()+"");
			intent.putExtra("price", mCart.getPrice()+"");
			//			intent.putExtra("proList", mCart);
			startActivity(intent);

		}

		//
		if( v == mAllSelectImage ){
			showLoadingDialog("");
			if( isAllSelect ){ //全选的时候，点击全部撤销
				new Thread(){
					public void run() {
						try {
							mCart = WebClient.getInstance(ShopCarActivity.this).unselectCart(select);
							mHandler.sendEmptyMessage(0);
						} catch (WebException e) {
							e.printStackTrace();
							dismissLoadingDialog();
						}
					};
				}.start();
			}else { // 只选择了一部分，点击全部选择
				new Thread(){
					public void run() {
						try {
							mCart = WebClient.getInstance(ShopCarActivity.this).selectCart(disSelect);
							mHandler.sendEmptyMessage(0);
						} catch (WebException e) {
							e.printStackTrace();
							dismissLoadingDialog();
						}
					};
				}.start();
			}

		}
	}


	/**
	 * 请求
	 * @param pageNum
	 * @param isRefresh
	 */
	private void updateShopCarList(final int pageNum,final boolean isRefresh){
		new Thread(){ 
			public void run() {
				try{
					WebClient client = WebClient.getInstance(ShopCarActivity.this);
					mCart = client.cart();
					mHandler.sendEmptyMessage(0);
				} catch (WebException e) {
					e.printStackTrace();
				}catch (Exception e) {
					App.showShortToast(R.string.unknownerror);
				}
			};
		}.start();

	}

	@SuppressLint("HandlerLeak") 
	final Handler mHandler = new Handler(){
		public void dispatchMessage(android.os.Message msg) {
			switch (msg.what) {
			case 0:
				dismissAllDialog();
				initData();
				mAdapter.update(mCart.getCartItems());
				mRefreshListView.onRefreshComplete();
				break;
			case 1:
				onRefresh(1);
				break;

			default:
				break;
			}
		}

	};

	private void initData() {

		if(mCart.getCartItems().size() == 0 ){
			isEmpty = true;
		}else {
			isEmpty = false;
		}
		//改变购物车数量的小图标
		PreferenceUtil.putInt(ShopCarActivity.this, "mProductSize", mCart.getAllQuantity());
		ContextUtil.sendBroadcast(ShopCarActivity.this, Constants.ACTION_UPDATEBADGE);

		//判断购物车是否为空
		if( isEmpty ){
			mShopCarRelat.setVisibility(View.GONE);
			mEmptyShopCaeRelat.setVisibility(View.VISIBLE);
			mShopCarTopRightBut.setVisibility(View.GONE);
			return;
		}else {
			mShopCarTopRightBut.setVisibility(View.VISIBLE);
			mShopCarRelat.setVisibility(View.VISIBLE);
			mEmptyShopCaeRelat.setVisibility(View.GONE);
		}

		int choise = 0; //选中的购物项的个数
		for (int i = 0; i < mCart.getCartItems().size(); i++) {
			if( mCart.getCartItems().get(i).isChosen() ){
				choise++;
			}
		}

		if( choise == mCart.getCartItems().size()){
			isAllSelect = true;
			mAllSelectImage.setImageResource(R.drawable.shopcar_check_in_one);
		}else {
			isAllSelect = false;
			mAllSelectImage.setImageResource(R.drawable.shopcar_check_one);
		}


		select = new long[choise]; // 选中的
		disSelect = new long[(mCart.getCartItems().size()-choise)]; //没选中的商品
		int j = 0;
		int h = 0;
		for (int i = 0; i <  mCart.getCartItems().size(); i++) {
			if( mCart.getCartItems().get(i).isChosen() ){ 
				select[j] = mCart.getCartItems().get(i).getId();//将选中的加入到long[]数组中
				j++;
			}else {
				disSelect[h] = mCart.getCartItems().get(i).getId();//将没选中的加入到long[]数组中
				h++;
			}
		}
		App.showLog("select=="+ Arrays.toString(select));

		totalpriceText.setText("￥"+mCart.getPrice());
		mSetAccountBut.setText("去结算("+mCart.getChosenQuantity()+")");
	};

	public class MyShopCarAdapter extends AbsViewHolderAdapter<CartItem>{

		public MyShopCarAdapter(Context context, int layoutRes) {
			super(context, layoutRes);
		}

		@Override
		protected void bindData(final int pos, final CartItem itemData) {
			LinearLayout mLin = getViewFromHolder(R.id.shopcar_item);
			ImageView  mcheck;  //
			ImageView mRemoveImage; 
			ImageView maddImage ;   //增一件商品
			ImageView mdeleteImage ;  //减一件商品
			EditText productCountsText; 
			RelativeLayout mCheckRelat;

			//			if("meal".equals(itemData.getType())){//套餐商品
			if(itemData.getCartItemBundle() != null){//套餐商品
				mLin.removeAllViews();
				LinearLayout convertView =  (LinearLayout) LayoutInflater.from(ShopCarActivity.this).inflate(R.layout.item_shopcar_meal_top, null);
				TextView proNameText = (TextView) convertView.findViewById(R.id.shopcar_item_meal_text);
				mcheck = (ImageView) convertView.findViewById(R.id.shopCheckBox1);
				mCheckRelat = (RelativeLayout) convertView.findViewById(R.id.check_relat1);
				mRemoveImage = (ImageView) convertView.findViewById(R.id.item_shopping_meal_top_delete_icon);
				maddImage = (ImageView) convertView.findViewById(R.id.item_shopping_top_add);
				mdeleteImage = (ImageView) convertView.findViewById(R.id.item_shopping_top_delete);
				productCountsText = (EditText) convertView.findViewById(R.id.product_top_counts);

				productCountsText.setText(itemData.getQuantity()+"");
				proNameText.setText(itemData.getCartItemBundle().getName());
				mLin.addView(convertView);
				for (int i = 0; i < itemData.getCartItemBundle().getProducts().size(); i++) {
					LinearLayout convertView1 = (LinearLayout) LayoutInflater.from(ShopCarActivity.this)
							.inflate(R.layout.item_shopcar_meal, null);

					RelativeLayout mRelat = (RelativeLayout) convertView1.findViewById(R.id.item_shopcar_relat);
					mRelat.setBackgroundResource(R.color.white);
					TextView productNameText = (TextView) convertView1.findViewById(R.id.item_shopcar_name_txt);
					TextView priceText = (TextView) convertView1.findViewById(R.id.item_shopcar_price_txt);
					TextView markpriceText = (TextView) convertView1.findViewById(R.id.item_shopcar_markprice_txt);
					TextView mPropertyText =(TextView) convertView1.findViewById(R.id.product_property);
					ImageView mImage1 =  (ImageView) convertView1.findViewById(R.id.item_shopcar_image);

					ImageLoader.getInstance().displayImage(itemData.getCartItemBundle().getProducts().get(i).getImage(), mImage1);
					productNameText.setText(itemData.getCartItemBundle().getProducts().get(i).getName());
					priceText.setText("￥"+itemData.getCartItemBundle().getProducts().get(i).getPrice());
					markpriceText.setText("￥"+itemData.getCartItemBundle().getProducts().get(i).getReferencePrice());
					markpriceText.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);  //在text中加一条线

					/** 商品的尺寸颜色等详情 */					
					//					List<SpecificationValues> mList = itemData.getCartItemBundle().getProducts().get(i);


					//					Map<String, String > maps = itemData.getProducts().get(i).getValues();
					//					mPropertyText.setText(getProductPropertyStr(maps));    // 商品颜色

					final int j = i;
					convertView1.setOnClickListener(new OnClickListener() {
						@Override
						public void onClick(View arg0) {
							long productID = itemData.getCartItemBundle().getProducts().get(j).getProductId();
							Intent intent = new Intent(ShopCarActivity.this,ProductDetailActivity.class);
							intent.putExtra("productID", productID+"");
							startActivity(intent);
						}
					});

					mLin.addView(convertView1);
				}

			}else {
				/** 非套餐商品的布局  */

				mLin.removeAllViews(); //清空布局容器
				LinearLayout convertView2 = (LinearLayout) LayoutInflater.from(ShopCarActivity.this).inflate(R.layout.item_shopcar_meal, null);

				RelativeLayout mRelat = (RelativeLayout) convertView2.findViewById(R.id.item_shopcar_relat);

				/** 判断商品是否为有效商品 */
				if( itemData.isValid()){
					mRelat.setBackgroundResource(R.color.setting_relat_bg_color);
				}else {
					mRelat.setBackgroundResource(R.color.invalid_shop_bg);
				}
				//-----------
				TextView productNameText = (TextView) convertView2.findViewById(R.id.item_shopcar_name_txt);
				productCountsText = (EditText) convertView2.findViewById(R.id.product_counts);
				TextView priceText = (TextView) convertView2.findViewById(R.id.item_shopcar_price_txt);
				TextView markpriceText = (TextView) convertView2.findViewById(R.id.item_shopcar_markprice_txt);
				TextView mPropertyText = (TextView) convertView2.findViewById(R.id.product_property);
				ImageView mImage = (ImageView) convertView2.findViewById(R.id.item_shopcar_image);
				maddImage = (ImageView) convertView2.findViewById(R.id.item_shopping_add);
				mdeleteImage = (ImageView) convertView2.findViewById(R.id.item_shopping_delete);
				mRemoveImage = (ImageView) convertView2.findViewById(R.id.item_shopping_delete_icon);

				LinearLayout mAddDelLin = (LinearLayout) convertView2.findViewById(R.id.shopcar_buttom_lin);
				mcheck = (ImageView) convertView2.findViewById(R.id.shopCheckBox);
				mCheckRelat = (RelativeLayout) convertView2.findViewById(R.id.check_relat);
				mcheck.setVisibility(View.VISIBLE);
				mAddDelLin.setVisibility(View.VISIBLE);
				mRemoveImage.setVisibility(View.VISIBLE);

				mLin.addView(convertView2);

				productNameText.setText(itemData.getItem().getName()); //商品名
				productCountsText.setText(itemData.getQuantity()+"");    //商品数量
				priceText.setText("￥"+itemData.getItemPayPrice());    //销售价 
				//				markpriceText.setText("￥"+itemData.getItemOldPrice());  //市场价
				//				markpriceText.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);  //在text中加一条线

				ImageLoader.getInstance().displayImage(itemData.getItem().getImage(), mImage);

				/** 商品的type 团购、特卖 */
				String PreferentialType =  itemData.getItem().getPreferentialType();

				//区分团购，特卖等商品----------------------------------------
				if( "featuredDeal".equals(PreferentialType)){
					App.showLog("getPreferentialType==featuredDeal");
					LabelView label = new LabelView(ShopCarActivity.this);
					label.setText(getString(R.string.featuredDeal));
					label.setBackgroundColor(getResources().getColor(R.color.red));
					label.setTargetView(mImage, 3, LabelView.Gravity.LEFT_TOP);
				}else if("groupBuying".equals(PreferentialType)){
					LabelView label = new LabelView(ShopCarActivity.this);
					App.showLog("getPreferentialType==groupBuying");
					label.setText(getString(R.string.groupBuying));
					label.setBackgroundColor(getResources().getColor(R.color.red));
					label.setTargetView(mImage, 3, LabelView.Gravity.LEFT_TOP);
				}else {

				}

				//商品的详细属性 Map----------------------------------------
				//				Map<String, String > maps = itemData.getProduct().getValues();
				//				mPropertyText.setText(getProductPropertyStr(maps));    // 商品属性

				List<Product.SpecificationValues> mList = itemData.getItem().getSpecificationValues();
				mPropertyText.setText(StringUtil.getProductPropertyforList(mList));    // 商品属性

			}

			//添加
			final int proNum = itemData.getQuantity();
			maddImage.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View arg0) {
					showLoadingDialog("");

					new Thread(){
						public void run() {
							try {
								mCart = WebClient.getInstance(ShopCarActivity.this).editCart(itemData.getId(), proNum+1);
								mHandler.sendEmptyMessage(0);
							} catch (WebException e) {
								e.printStackTrace();
							}
						};
					}.start();	

				}
			});
			//减少商品数量，当数量为一时删除
			mdeleteImage.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View arg0) {

					if (proNum == 1) {
						showDeleteDialog(itemData.getId());
					}else {
						showLoadingDialog("");
						new Thread(){
							public void run() {
								try {
									mCart = WebClient.getInstance(ShopCarActivity.this).editCart(itemData.getId(), proNum-1);
									mHandler.sendEmptyMessage(0);
								} catch (WebException e) {
									dismissLoadingDialog();
									e.printStackTrace();
								}
							};
						}.start();	
					}
				}
			});


			mRemoveImage.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View arg0) {
					showDeleteDialog(itemData.getId());
				}
			});


			final long[] ads = new long[1];
			ads[0] = itemData.getId();
			//设置选中与非选中时的图片
			if(itemData.isChosen()){
				mcheck.setBackgroundResource(R.drawable.shopcar_check_in_one);
			}else {
				mcheck.setBackgroundResource(R.drawable.shopcar_check_one);
			}
			//选择商品与撤销商品
			mCheckRelat.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View paramView) {
					showLoadingDialog("");
					if(itemData.isChosen()){
						new Thread(){
							public void run() {
								try {
									//撤销选择
									mCart = WebClient.getInstance(ShopCarActivity.this).unselectCart(ads);
									mHandler.sendEmptyMessage(0);
								} catch (Exception e) {
									dismissLoadingDialog();
									App.showShortToast("操作失败!");
								}
							};
						}.start();
					}else {
						new Thread(){
							public void run() {
								try {
									//选择
									mCart = WebClient.getInstance(ShopCarActivity.this).selectCart(ads);
									mHandler.sendEmptyMessage(0);
								} catch (Exception e) {
									dismissLoadingDialog();
									App.showShortToast("操作失败!");
								}
							};
						}.start();
					}
				}
			});

		}
	}





	@Override
	public boolean onItemLongClick(AdapterView<?> parent,
			View view, int position, long id) {

		final long cid = mAdapter.getData().get(position).getId();
		showDeleteDialog(cid);

		return true;
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view,
			int position, long id) {

		//		if("meal".equals(mAdapter.getData().get(position).getType())){
		if(mAdapter.getData().get(position).getCartItemBundle() != null ){

		}else {
			long productID = mAdapter.getData().get(position).getItem().getProductId();
			Intent intent = new Intent(ShopCarActivity.this,ProductDetailActivity.class);
			intent.putExtra("productID", productID+"");
			startActivity(intent);
		}

	}

	@Override
	public void onRefresh(int page) {
		updateShopCarList(1, true);
	}

	@Override
	public void onLoadMore(int page) {
	}

	@Override
	protected void onResume() {
		super.onResume();

		//判断是否是第一次进入，第一次进入不在这刷新
		if( isFirst ){
			isFirst = false;
		}else {
			onRefresh(1);
		}

		//判断购物车是否为空
		App.showLog("isEmpty=="+isEmpty);
		if( isEmpty ){
			mShopCarRelat.setVisibility(View.GONE);
			mEmptyShopCaeRelat.setVisibility(View.VISIBLE);
			mShopCarTopRightBut.setVisibility(View.GONE);
			return;
		}else {
			mShopCarTopRightBut.setVisibility(View.VISIBLE);
			mShopCarRelat.setVisibility(View.VISIBLE);
			mEmptyShopCaeRelat.setVisibility(View.GONE);
		}

	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		dismissDeleteDialog();
		dismissRemoveDialog();
		mHandler.removeCallbacksAndMessages(null);
	}

	protected void showDeleteDialog(final long ids) {
		dismissDeleteDialog();
		dismissRemoveDialog();
		mDoubleDialog = new DoubleButtonDialog(this);
		mDoubleDialog.showDialog(getString(R.string.info_delete_this), new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				showLoadingDialog("");
				new Thread(){
					public void run() {
						try {
							mCart = WebClient.getInstance(ShopCarActivity.this).deleteCart(ids);
							mHandler.sendEmptyMessage(0);
						} catch (WebException e) {
							dismissLoadingDialog();
							dismissDeleteDialog();
							e.printStackTrace();
						}
					};
				}.start();
			}
		});

	}

	/** 取消dialog */
	private void dismissDeleteDialog() {

		if( mDoubleDialog != null && mDoubleDialog.isShowing() ) {
			mDoubleDialog.dismiss();
		}
		mDoubleDialog = null;

	}
	protected void showRemoveDialog() {
		dismissDeleteDialog();
		dismissRemoveDialog();
		mDoubleRemoveDialog = new DoubleButtonDialog(this);
		mDoubleRemoveDialog.showDialog(getString(R.string.info_remove_this), new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				showLoadingDialog("");
				new Thread(){
					public void run() {
						try {
							mCart = WebClient.getInstance(ShopCarActivity.this).clearCart();
							mHandler.sendEmptyMessage(0);
						} catch (WebException e) {
							dismissLoadingDialog();
							dismissDeleteDialog();
							e.printStackTrace();
						}
					};
				}.start();
			}
		});

	}

	/** 取消dialog */
	private void dismissRemoveDialog() {

		if( mDoubleRemoveDialog != null && mDoubleRemoveDialog.isShowing() ) {
			mDoubleRemoveDialog.dismiss();
		}
		mDoubleRemoveDialog = null;

	}

}
